<?php 
header("Content-type: text/html; charset=utf-8");
include('db.inc.php');


//&result 引用的变量

function getList($pid=0,&$result=array(),$spac=0){
	//$spac=0 为了使分级缩进距离
	$spac = $spac+2;
	$sql = "select * from deepcate where pid = $pid";
	$res = mysql_query($sql);
	//参数里定义成了数组,不需要再定义
	//$result = array();
	//var_dump($row);
	while($row = mysql_fetch_assoc($res)){
		$row['catename'] = str_repeat('&nbsp;',$spac).'|--'.$row['catename'];
		$result[] = $row;
		//此处查询到的id,即是子类的pid
		getList($row['id'],$result,$spac);
	}
	return $result;
}

$rs = getList();
//print_r($rs);
foreach ($rs as $key => $value) {
	echo "<option> {$value['catename']} </option>";
}


?>